namespace RivercrabNet
{
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Drawing;
    using System.Drawing.Drawing2D;

    public class IndicatorDetrendedPriceOscillator : BaseIndicator
    {
        private string maField = ("DPO.MAFIELD." + Common.GetGuid());
        private LineShape tlsDpo;
        private LineShape tlsMDpo;

        public IndicatorDetrendedPriceOscillator()
        {
            base.IndType = IndicatorType.DPO;
            base.IndName = "DPO";
            base.IndDesc = "区间震荡线";
            base.IndPeriod.Add(new IndicatorPeriod(0, "N1", 20.0));
            base.IndPeriod.Add(new IndicatorPeriod(1, "N2", 11.0));
            base.IndPeriod.Add(new IndicatorPeriod(2, "N3", 6.0));
            base.SourceDic["Close"] = "";
            base.fields = new string[] { "DPO", "MDPO" };
        }

        public override bool Contains(object obj)
        {
            if ((obj != this.tlsDpo) && (obj != this.tlsMDpo))
            {
                return false;
            }
            return true;
        }

        public override double[] Get(int r)
        {
            double curValue = Convert.ToDouble(base.Crab.DataSource.Rows[r][base.SourceDic["Close"]]);
            double num2 = Common.CalcuteMovingAvg(r, (int) base.IndPeriod[0].ParamValue, this.maField, base.SourceDic["Close"], curValue, base.Crab.DataSource);
            double num3 = 0.0;
            if (r >= ((int) base.IndPeriod[1].ParamValue))
            {
                num3 = Convert.ToDouble(base.Crab.DataSource.Rows[r - ((int) base.IndPeriod[1].ParamValue)][this.maField]);
            }
            double num4 = curValue - num3;
            double num5 = Common.CalcuteMovingAvg(r, (int) base.IndPeriod[2].ParamValue, this.tlsMDpo.Name, this.tlsDpo.Name, num4, base.Crab.DataSource);
            return new double[] { num2, num4, num5 };
        }

        public override List<BaseShape> GetShapeList()
        {
            return new List<BaseShape> { this.TlsDpo, this.TlsMDpo };
        }

        public override void Remove()
        {
            base.Crab.DeleteShape(this.TlsDpo);
            base.Crab.DeleteShape(this.TlsMDpo);
            base.Crab.DataSource.Columns.Remove(this.MaField);
        }

        public override bool Set(int r, string target)
        {
            try
            {
                DataRow row = base.Crab.DataSource.Rows[r];
                foreach (string str in base.SourceDic.Values)
                {
                    if ((str == target) || (target == null))
                    {
                        foreach (string str2 in base.SourceDic.Values)
                        {
                            if (row[str2] is DBNull)
                            {
                                return false;
                            }
                        }
                        double[] numArray = this.Get(r);
                        base.Crab.SetValue(this.MaField, numArray[0], r);
                        base.Crab.SetValue(this.TlsDpo.Name, numArray[1], r);
                        base.Crab.SetValue(this.TlsMDpo.Name, numArray[2], r);
                        return true;
                    }
                }
                return false;
            }
            catch
            {
                return false;
            }
        }

        public override void SetParam(string[] fields, string[] source, double[] periods, int panelID)
        {
            base.SourceDic["Close"] = source[0];
            base.IndPeriod[0].ParamValue = periods[0];
            base.IndPeriod[1].ParamValue = periods[1];
            base.IndPeriod[2].ParamValue = periods[2];
            this.TlsDpo = base.Crab.AddLine(fields[0], panelID);
            base.Crab.SetLine(fields[0], fields[0], Color.White, 1, 0.01, 2, DashStyle.Solid);
            this.TlsMDpo = base.Crab.AddLine(fields[1], panelID);
            base.Crab.DataSource.Columns.Add(this.MaField);
        }

        public string MaField
        {
            get
            {
                return this.maField;
            }
            set
            {
                this.maField = value;
            }
        }

        public LineShape TlsDpo
        {
            get
            {
                return this.tlsDpo;
            }
            set
            {
                this.tlsDpo = value;
            }
        }

        public LineShape TlsMDpo
        {
            get
            {
                return this.tlsMDpo;
            }
            set
            {
                this.tlsMDpo = value;
            }
        }
    }
}

